package com.gt.admin.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gt.common.annotation.Log;
import com.gt.common.core.controller.BaseController;
import com.gt.common.core.domain.AjaxResult;
import com.gt.common.core.page.TableDataInfo;
import com.gt.common.enums.BusinessType;
import com.gt.admin.domain.QuestionnaireModel;
import com.gt.admin.domain.vo.QuestionnaireModelVO;
import com.gt.admin.service.IQuestionnaireModelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 筛查问卷controller
 */
@Api(tags = "sc-筛查问卷模板")
@RestController
@RequestMapping("/screening-questionnaire")
public class QuestionnaireModelController extends BaseController {
    @Autowired
    private IQuestionnaireModelService questionnaireModelService;

    /**
     * 查询所有筛查问卷模板
     */
    @ApiOperation("查询所有筛查问卷模板")
    @GetMapping
    public TableDataInfo list(QuestionnaireModel questionnaireModel){
        startPage();
        LambdaQueryWrapper<QuestionnaireModel> queryWrapper = new LambdaQueryWrapper<>(questionnaireModel);
        List<QuestionnaireModel> list = questionnaireModelService.list(queryWrapper);
        return getDataTable(list);
    }

    /**
     * 按superid查询版本
     */
    @ApiOperation("按superid查询版本")
    @GetMapping("/version/{superid}")
    public AjaxResult listVersion(@PathVariable("superid")Long superid){
        return AjaxResult.success(questionnaireModelService.selectVersion(superid));
    }

    /**
     * 按superid查询筛查问卷模板
     */
    @ApiOperation("按superid查询问卷模板")
    @GetMapping("/{superid}")
    public AjaxResult listBySuperId(@PathVariable("superid")Long superid){
        return AjaxResult.success(questionnaireModelService.selectBySuperId(superid));
    }

    /**
     * 新增或修改筛查问卷模板
     */
    @ApiOperation("新增或修改筛查问卷模板")
    @Log(title = "筛查问卷模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult update(@RequestBody QuestionnaireModelVO questionnaireModelVO){
        return toAjax(questionnaireModelService.updateByVersion(questionnaireModelVO));
    }

    /**
     * 删除筛查问卷模板和模板下的分类
     */
    @ApiOperation("删除筛查问卷模板")
    @Log(title = "筛查问卷模板", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        return toAjax(questionnaireModelService.deleteById(id));
    }
}
